package controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigInteger;
import java.sql.SQLException;

import model.Model;
import model.NoMoneyExeption;
import UserInterface.*;

public class Controller {
	UserInterface intefaceView;
	Model theModel;
	Controller(UserInterface intefaceView,Model theModel){
		this.intefaceView= intefaceView;
		this.theModel=theModel;
		this.intefaceView.addMantainanceActionPannel();
		this.intefaceView.seBankBalanceActionListener(new SeeBankBalanceListener());
		this.intefaceView.setMoneyListener(new SetMoneyListener());
		this.intefaceView.allowUsersActionListener(new AllowUsersAction());
		this.intefaceView.addPutCardListener(new PutCardListener());
		this.intefaceView.addMaintananceInputBillConfirm(new MaintananceInput());
		this.intefaceView.addShowBalanceListener(new ShowBankBalanceList());
		this.intefaceView.getPutNumberCard().putListenerOk(new PutCardOkListener());
		this.intefaceView.getPutPinCode().putListenerOk(new PutPinCodeOkListener());
		this.intefaceView.getPutNumberCard().putListenerCancel(new PutCardCancelListener());
		this.intefaceView.getPutPinCode().putListenerCancel(new PutPinCodeCancelListener());
		this.intefaceView.getPutNumberCard().putListenerChange(new PutCardChangeListener());
		this.intefaceView.getPutPinCode().putListenerChange(new PutPinCodeChangeListener());
		this.intefaceView.getPutNumberCard().putNumbers();
		this.intefaceView.getPutPinCode().putNumbers();
		this.intefaceView.getChooseOperation().addGetMoneyListener(new GetMoneyListener());
		this.intefaceView.getChooseOperation().addCheckBalanceListener(new CheckBalenceListener());
		this.intefaceView.getChooseOperation().addTransferToAnotherListener(new TransferToAnotherAccount());
		this.intefaceView.getChooseOperation().addRechargeMobileListener(new MobileListener());
		this.intefaceView.getChooseOperation().addCancel(new CancelChooseOperation() );
		this.intefaceView.getShowUserBalance().setUserBalanceOkListener(new UserBalanceOkListener());
		this.intefaceView.getShowUserBalance().setUserBalanceCancelListener(new UserBalanceCancelListener());
		this.intefaceView.getShowUserBalance().setUserBalanceBackListener(new UserBalanceBackListener());
		this.intefaceView.getMoneyChooseSum().addCancelListener(new UserBalanceCancelListener());
		this.intefaceView.getMoneyChooseSum().addBackListener(new GetMoneyBackListener());
		this.intefaceView.getMoneyChooseSum().addAnotherAmountList(new PutAnotheAmountListener());
		this.intefaceView.getMoneyChooseSum().addSum10ActionListener(new Withdraw10Listener());
		this.intefaceView.getMoneyChooseSum().addSum50ActionListener(new Withdraw50Listener());
		this.intefaceView.getMoneyChooseSum().addSum100ActionListener(new Withdraw100Listener());
		this.intefaceView.getMoneyChooseSum().addSum200ActionListener(new Withdraw200Listener());
		this.intefaceView.getMoneyFinish().addOkListener(new MoneyFinishList());
		this.intefaceView.getMoneyAnotherSum().putListenerOk(new GetAnotherSumOkListener());
		this.intefaceView.getMoneyAnotherSum().putNumbers();
		this.intefaceView.getMoneyAnotherSum().putListenerCancel(new GetAnotherSumCancelListener());
		this.intefaceView.getMoneyAnotherSum().putListenerChange(new GetAnotherSumChangeListener());
		this.intefaceView.getMoneyAnotherSum().putListenerBack(new GetAnotherSumBackListener());
		this.intefaceView.getEnterAccount().putNumbers();
		this.intefaceView.getEnterAccount().putListenerOk(new TransferToAnotherAccountOK());
		this.intefaceView.getEnterAccount().putListenerCancel(new TransferToAnotherAccountCancel());
		this.intefaceView.getEnterAccount().putListenerBack(new TransferToAnotherAccountBack());
		this.intefaceView.getEnterAccount().putListenerChange(new TransferToAnotherAccountChange());
		this.intefaceView.getEnterMobileNumber().putNumbers();
		this.intefaceView.getEnterMobileNumber().putListenerOk(new EnterMobilePhoneOK());
		this.intefaceView.getEnterMobileNumber().putListenerCancel(new EnterMobilePhoneCancel());
		this.intefaceView.getEnterMobileNumber().putListenerBack(new EnterMobilePhoneBack());
		this.intefaceView.getEnterMobileNumber().putListenerChange(new EnterMobilePhoneChange());
		this.intefaceView.getEnterSumForChargeAcount().putListenerOk(new GetPayPhoneOkListener());
		this.intefaceView.getEnterSumForChargeAcount().putNumbers();
		this.intefaceView.getEnterSumForChargeAcount().putListenerCancel(new GetPayPhoneCancelListener());
		this.intefaceView.getEnterSumForChargeAcount().putListenerChange(new GePayPhoneChangeListener());
		this.intefaceView.getEnterSumForChargeAcount().putListenerBack(new GePayPhoneBackListener());
		
		this.intefaceView.getSumForTransferToAnother().putListenerOk(new SumToAnotherOkListener());
		this.intefaceView.getSumForTransferToAnother().putNumbers();
		this.intefaceView.getSumForTransferToAnother().putListenerCancel(new SumToAnotherCancelListener());
		this.intefaceView.getSumForTransferToAnother().putListenerChange(new SumToAnotherChangeListener());
		this.intefaceView.getSumForTransferToAnother().putListenerBack(new SumToAnotherBackListener());
		this.intefaceView.getFinishTransfer().setOkListener(new GetFinishTransferToAnother());
		
		this.intefaceView.getFinishRechargeMobile().setOkListener(new FinishPayPhone());
			//this.intefaceView.getPutNumberCard().putNumbersListener(new PutCardNumberListener());
	}
	class FinishPayPhone implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addChooseOperation();
			intefaceView.getMoneyAnotherSum().setS("");
			intefaceView.getEnterAccount().setS("");
			intefaceView.getEnterMobileNumber().setS("");
			intefaceView.getEnterSumForChargeAcount().setS("");
			intefaceView.getSumForTransferToAnother().setS("");
			
		}
		
	}
	class GetFinishTransferToAnother implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			intefaceView.addChooseOperation();
			intefaceView.getMoneyAnotherSum().setS("");
			intefaceView.getEnterAccount().setS("");
			intefaceView.getEnterMobileNumber().setS("");
			intefaceView.getEnterSumForChargeAcount().setS("");
			intefaceView.getSumForTransferToAnother().setS("");
			
			
		}
		
	}
	class SumToAnotherChangeListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.getSumForTransferToAnother().setS("");
			
		}
		
	}
	
	class SumToAnotherBackListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.getSumForTransferToAnother().setS("");
			intefaceView.addEnterAccountNumber();
			
		}
		
	}
	
	class SumToAnotherOkListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			try {
				if (intefaceView.getSumForTransferToAnother().getS().equals(""))
				{
					intefaceView.showMassage("Invalid sum to transfer");
					intefaceView.getSumForTransferToAnother().setS("");
				} else{
				if(theModel.checkCard(new BigInteger(intefaceView.getEnterAccount().getS()))){
					
					try {
						theModel.takeMoney(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()),Integer.parseInt(intefaceView.getSumForTransferToAnother().getS()));
						theModel.putMoneyToAcount(new BigInteger(intefaceView.getEnterAccount().getS()),Integer.parseInt(intefaceView.getSumForTransferToAnother().getS()));
						intefaceView.addFinishTransferToAnthAccount();
						intefaceView.getFinishTransfer().setNumberAcount(intefaceView.getEnterAccount().getS());
						intefaceView.getFinishTransfer().setAmountToTransfer(intefaceView.getSumForTransferToAnother().getS());
						intefaceView.getFinishTransfer().setBalance(Integer.toString(theModel.getBalance(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()))));
					} catch (NumberFormatException e1) {
						intefaceView.showMassage("Mistake occured");
					} catch (Exception e1) {
						intefaceView.showMassage("You could not transfer this sum because of your  balance");
						intefaceView.getSumForTransferToAnother().setS("");
					}
				}
				else{
					intefaceView.showMassage("Invalid card number");
					intefaceView.getEnterAccount().setS("");
				}
				}
			} catch (SQLException e1) {
				intefaceView.showMassage("Couldn't connect ro database");
			}
			
			
		}
		
	}
	
	class SumToAnotherCancelListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addFirstUsersPage();
			intefaceView.getPutPinCode().setS("");
			intefaceView.getPutNumberCard().setS("");
			intefaceView.getMoneyAnotherSum().setS("");
			intefaceView.getEnterAccount().setS("");
			intefaceView.getEnterMobileNumber().setS("");
			intefaceView.getEnterSumForChargeAcount().setS("");
			intefaceView.getSumForTransferToAnother().setS("");			
		}
		
	}
	class GePayPhoneBackListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.getEnterSumForChargeAcount().setS("");
			intefaceView.getEnterMobileNumber();
			
		}
		
	}
	class GetPayPhoneOkListener implements ActionListener{
//TODO
		@Override
		public void actionPerformed(ActionEvent e) {
			if (intefaceView.getEnterSumForChargeAcount().getS().equals(""))
			{
				intefaceView.showMassage("Invalid sum to transfer");
				intefaceView.getEnterSumForChargeAcount().setS("");
			} else{
			
				
				try {
					theModel.takeMoney(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()),Integer.parseInt(intefaceView.getEnterSumForChargeAcount().getS()));
					intefaceView.addFinishRechargeMobile();
					intefaceView.getFinishRechargeMobile().setPhoneNumber("0"+intefaceView.getEnterMobileNumber().getS());
					intefaceView.getFinishRechargeMobile().setAmountToTransfer(intefaceView.getEnterSumForChargeAcount().getS());
					intefaceView.getFinishRechargeMobile().setBalance(Integer.toString(theModel.getBalance(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()))));
				} catch (NumberFormatException e1) {
					intefaceView.showMassage("Mistake occured");
				} catch (Exception e1) {
					intefaceView.showMassage("You could not transfer this sum because of your  balance");
					intefaceView.getSumForTransferToAnother().setS("");
			}
			
			}
			
			
		}
		
	}
	class GetPayPhoneCancelListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addFirstUsersPage();
			intefaceView.getPutPinCode().setS("");
			intefaceView.getPutNumberCard().setS("");
			intefaceView.getMoneyAnotherSum().setS("");
			intefaceView.getEnterAccount().setS("");
			intefaceView.getEnterMobileNumber().setS("");
			intefaceView.getEnterSumForChargeAcount().setS("");
			
		}
		
	}
	
	class GePayPhoneChangeListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.getEnterSumForChargeAcount().setS("");
			
		}
		
	}
	class GetAnotherSumBackListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addUserChooseMoneyToWithdraw();
			intefaceView.getMoneyAnotherSum().setS("");
			
		}
		
	}
	class EnterMobilePhoneOK implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			if (intefaceView.getEnterMobileNumber().getS().equals("")||(intefaceView.getEnterMobileNumber().getS().length()<9))
			{
				intefaceView.showMassage("Invalid phone number");
				intefaceView.getEnterMobileNumber().setS("");
			} else{
				intefaceView.addEnterSumForChargeAcount();
			}
		}
		
	}
	
	class EnterMobilePhoneCancel implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addFirstUsersPage();
			intefaceView.getPutPinCode().setS("");
			intefaceView.getPutNumberCard().setS("");
			intefaceView.getMoneyAnotherSum().setS("");
			intefaceView.getEnterAccount().setS("");
			intefaceView.getEnterMobileNumber().setS("");
			
		}
		
	}
	
	class EnterMobilePhoneBack implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addChooseOperation();
			intefaceView.getEnterMobileNumber().setS("");
			
		}
		
	}
	class EnterMobilePhoneChange implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.getEnterMobileNumber().setS("");
			
		}
		
	}
	class TransferToAnotherAccountCancel implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addFirstUsersPage();
			intefaceView.getPutPinCode().setS("");
			intefaceView.getPutNumberCard().setS("");
			intefaceView.getMoneyAnotherSum().setS("");
			intefaceView.getEnterAccount().setS("");
		}
		
	}
	class TransferToAnotherAccountBack implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addChooseOperation();
			intefaceView.getEnterAccount().setS("");
			
		}
		
	}
	class TransferToAnotherAccountChange implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.getEnterAccount().setS("");
			
		}
		
	}
	class TransferToAnotherAccountOK implements ActionListener{

		@Override
		
		public void actionPerformed(ActionEvent e) {
			try {
				if (intefaceView.getEnterAccount().getS().equals("")||intefaceView.getEnterAccount().getS().equals(intefaceView.getPutNumberCard().getS()))
				{
					intefaceView.showMassage("Invalid card number");
					intefaceView.getEnterAccount().setS("");
				} else{
				if(theModel.checkCard(new BigInteger(intefaceView.getEnterAccount().getS()))){
					intefaceView.addSumForTransferToAnother();
					//intefaceView.getPutNumberCard().clearS();
					//intefaceView.getPutNumberCard().setS("");
				}
				else{
					intefaceView.showMassage("Invalid card number");
					intefaceView.getEnterAccount().setS("");
				}
				}
			} catch (SQLException e1) {
				intefaceView.showMassage("Couldn't connect ro database");
			}
			
			
		}
		
	}
	class GetAnotherSumChangeListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
			intefaceView.getMoneyAnotherSum().setS("");
		}
		
	}
	class GetAnotherSumCancelListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addFirstUsersPage();
			intefaceView.getPutPinCode().setS("");
			intefaceView.getPutNumberCard().setS("");
			intefaceView.getMoneyAnotherSum().setS("");
			
		}
		
	}
	class GetAnotherSumOkListener implements ActionListener{
//TODO
		@Override
		public void actionPerformed(ActionEvent e) {
		
			
				if (intefaceView.getMoneyAnotherSum().getS().equals("")||(Integer.valueOf(intefaceView.getMoneyAnotherSum().getS())%10!=0))
				{
					intefaceView.showMassage("Invalid sum");
					intefaceView.getMoneyAnotherSum().setS("");
				} else{
					try {
						if( theModel.getBalance(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()))>Integer.valueOf(intefaceView.getMoneyAnotherSum().getS())){
							
							
							//intefaceView.addGettingMoney();
							try {
								theModel.withdraw(Integer.valueOf(intefaceView.getMoneyAnotherSum().getS()));
								theModel.takeMoney(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()),Integer.valueOf(intefaceView.getMoneyAnotherSum().getS()) );
								
								intefaceView.getMoneyFinish().putSum(intefaceView.getMoneyAnotherSum().getS());
								intefaceView.getMoneyFinish().putBalance(Integer.toString(theModel.getBalance(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()))));
								
							} catch (NumberFormatException e1) {
								intefaceView.showMassage("Some trable happened");
							} catch(NoMoneyExeption e1){
								intefaceView.showMassage("Atm have not this money");
								intefaceView.getMoneyAnotherSum().setS("");
							}
							catch (Exception e1) {
								intefaceView.showMassage("You can't withdraw money because your balance is lower than wanted sum");
								intefaceView.getMoneyAnotherSum().setS("");
							}
							}
							else{
								intefaceView.showMassage("Choose another sum because there is't so much in ATM");
							}
					} catch (NumberFormatException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
			
		
				}}
	}
	class Withdraw10Listener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
			try {
				if( theModel.getAmountOf10()>0){
					
				
				intefaceView.addGettingMoney();
				try {
					
					theModel.takeMoney(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()), 10);
					theModel.withdrawTen(1);
					intefaceView.getMoneyFinish().putSum("10");
					intefaceView.getMoneyFinish().putBalance(Integer.toString(theModel.getBalance(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()))));
					
				} catch (NumberFormatException e1) {
					intefaceView.showMassage("Some trable happened");
				} catch(NoMoneyExeption e1){
					intefaceView.showMassage("Atm have not this money");
				}
				catch (Exception e1) {
					intefaceView.showMassage("You can't withdraw money because your balance is lower than wanted sum");;
				}
				}
				else{
					intefaceView.showMassage("Choose another sum because there is't 10 UAN in ATM");
				}
			} catch (SQLException e1) {
				intefaceView.showMassage("Couldn't connect to database");
			}
			
		}
		
	}
	class Withdraw50Listener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
			try {
				if( theModel.getAmountOf50()>0){
					
				
				intefaceView.addGettingMoney();
				try {
					
					theModel.takeMoney(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()), 50);
					theModel.withdrawFifty(1);
					intefaceView.getMoneyFinish().putSum("50");
					intefaceView.getMoneyFinish().putBalance(Integer.toString(theModel.getBalance(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()))));
					
				} catch (NumberFormatException e1) {
					intefaceView.showMassage("Some trable happened");
				} catch(NoMoneyExeption e1){
					intefaceView.showMassage("Atm have not this money");
				}
				catch (Exception e1) {
					intefaceView.showMassage("You can't withdraw money because your balance is lower than wanted sum");;
				}
				}
				else{
					intefaceView.showMassage("Choose another sum because there is't 50 UAN in ATM");
				}
			} catch (SQLException e1) {
				intefaceView.showMassage("Couldn't connect to database");
			}
			
			
		}
		
	}
	class MoneyFinishList implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			intefaceView.addChooseOperation();
			
		}
		
	}
	class Withdraw100Listener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
			try {
				if( theModel.getAmountOf100()>0){
					
				
				intefaceView.addGettingMoney();
				try {
					
					theModel.takeMoney(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()), 100);
					theModel.withdrawHundred(1);
					intefaceView.getMoneyFinish().putSum("100");
					intefaceView.getMoneyFinish().putBalance(Integer.toString(theModel.getBalance(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()))));
					
				} catch (NumberFormatException e1) {
					intefaceView.showMassage("Some trable happened");
				} catch (Exception e1) {
					intefaceView.showMassage("You can't withdraw money because your balance is lower than wanted sum");;
				}
				}
				else{
					intefaceView.showMassage("Choose another sum because there is't 100 UAN in ATM");
				}
			} catch (SQLException e1) {
				intefaceView.showMassage("Couldn't connect to database");
			}
			
		}
		
	}
	class Withdraw200Listener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
		
			try {
				if( theModel.getAmountOf200()>0){
					
				
				intefaceView.addGettingMoney();
				try {
					
					theModel.takeMoney(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()), 200);
					theModel.withdrawTwoHandred(1);
					intefaceView.getMoneyFinish().putSum("200");
					intefaceView.getMoneyFinish().putBalance(Integer.toString(theModel.getBalance(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()))));
					
				} catch (NumberFormatException e1) {
					intefaceView.showMassage("Some trable happened");
					
				}
				catch(NoMoneyExeption e1){
					intefaceView.showMassage("Atm have not this money");
				}
				catch (Exception e1) {
					intefaceView.showMassage("You can't withdraw money because your balance  is lower than wanted sum");;
				}
				}
				else{
					intefaceView.showMassage("Choose another sum because there is't 200 UAN in ATM");
				}
			} catch (SQLException e1) {
				intefaceView.showMassage("Couldn't connect to database");
			}
			
		}
		
	}
	class PutAnotheAmountListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addGetAnotherSumForm();
			
		}
		
	}
	class GetMoneyBackListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addChooseOperation();
			
		}
		
	}
	class UserBalanceBackListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addChooseOperation();
			
		}
		
	}
	class UserBalanceOkListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			intefaceView.addChooseOperation();
			
		}
		
	}
	class UserBalanceCancelListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addFirstUsersPage();
			intefaceView.getPutPinCode().setS("");
			intefaceView.getPutNumberCard().setS("");
			
		}
		
	}
	class CancelChooseOperation implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
			intefaceView.addFirstUsersPage();
			intefaceView.getPutPinCode().setS("");
			intefaceView.getPutNumberCard().setS("");
			
		}
		
	}
	class MobileListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addEnterMobileNumber();
			
		}
		
	}
	class TransferToAnotherAccount implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) { 
			intefaceView.addEnterAccountNumber();
			
		}
		
	}
	class CheckBalenceListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
			intefaceView.addShowUserBalance();	
			try {
				intefaceView.getShowUserBalance().setBalance(theModel.getBalance(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS())));
			} catch (NumberFormatException e1) {
				intefaceView.showMassage("Incorrect Number");
			} catch (SQLException e1) {
				intefaceView.showMassage("Couldn't connect to database");
			}
		}
		
	}
	
	class GetMoneyListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			intefaceView.addUserChooseMoneyToWithdraw();
			
		}
		
	}
	
	class PutPinCodeChangeListener implements ActionListener{
		
				@Override
				public void actionPerformed(ActionEvent arg0) {
					intefaceView.getPutPinCode().setS("");
					
				}
				
			}
			
			class PutCardChangeListener implements ActionListener{

					@Override
				public void actionPerformed(ActionEvent e) {
					intefaceView.getPutNumberCard().setS("");
				}
				
			}
	class PutPinCodeCancelListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			intefaceView.addFirstUsersPage();
			intefaceView.getPutPinCode().setS("");
			intefaceView.getPutNumberCard().setS("");
			
		}
		
	}
	
	class PutCardCancelListener implements ActionListener{

			@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.getPutNumberCard().clearS();
			intefaceView.getPutNumberCard().setS("");
			intefaceView.addFirstUsersPage();
			
			
		}
		
	}
	class PutPinCodeOkListener implements ActionListener{
		
		@Override
		public void actionPerformed(ActionEvent arg0) {
			
			try {
				if (intefaceView.getPutPinCode().getS().equals(""))
				{
					intefaceView.showMassage("Invalid card number");
					intefaceView.getPutPinCode().setS("");
				} else{
				if(theModel.checkAccount(new BigInteger(intefaceView.getPutNumberCard().getS()),Integer.valueOf(intefaceView.getPutPinCode().getS()))){
					intefaceView.addChooseOperation();
				}
				else{
					intefaceView.showMassage("Invalid card number");
					intefaceView.getPutPinCode().setS("");
				}
				}
			} catch (SQLException e) {
				intefaceView.showMassage("Couldn't connect ro database");
			}
			
			
		}
		
	}
	
	class PutCardOkListener implements ActionListener{
		
		@Override
		public void actionPerformed(ActionEvent arg0) {
			
			try {
				if (intefaceView.getPutNumberCard().getS().equals(""))
				{
					intefaceView.showMassage("Invalid card number");
					intefaceView.getPutNumberCard().setS("");
				} else{
				if(theModel.checkCard(new BigInteger(intefaceView.getPutNumberCard().getS()))){
					intefaceView.addPutPinCode();
					//intefaceView.getPutNumberCard().clearS();
					//intefaceView.getPutNumberCard().setS("");
				}
				else{
					intefaceView.showMassage("Invalid card number");
					intefaceView.getPutNumberCard().setS("");
				}
				}
			} catch (SQLException e) {
				intefaceView.showMassage("Couldn't connect ro database");
			}
			
			
		}
		
	}

	class ShowBankBalanceList implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addMantainanceActionPannel();
		}
		
	}
	class MaintananceInput implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
		
			try{
			int ten=Integer.valueOf(intefaceView.getInputMaintanance().get10());
			int fifty=Integer.valueOf(intefaceView.getInputMaintanance().get50());
			int hundred=Integer.valueOf(intefaceView.getInputMaintanance().get100());
			int twoHundred=Integer.valueOf(intefaceView.getInputMaintanance().get200());
		
				theModel.putMoneyToATM(ten, fifty, hundred, twoHundred);
			
			intefaceView.addShowBalancleOFATM();
			int[] mas;
			try {
				mas = theModel.getMoney();
				intefaceView.showATMBalance().putText10(Integer.toString(mas[0]));
				intefaceView.showATMBalance().putText50(Integer.toString(mas[1]));
				intefaceView.showATMBalance().putText100(Integer.toString(mas[2]));
				intefaceView.showATMBalance().putText200(Integer.toString(mas[3]));
				
			} catch (SQLException e1) {
				intefaceView.showMassage("The mistake happened");
			}
			//intefaceView.seBankBalanceActionListener(new SeeBankBalanceListener());
			
			}
			catch (NumberFormatException e){
				intefaceView.showMassage("Incorrect amount of money");
			} catch (Exception e) {
				intefaceView.showMassage("Couldnot connect to database");
			}
			
		}
		
	}
	 class AllowUsersAction implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addFirstUsersPage();
		}
		 
	 }
	class SetMoneyListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addInputValuta();
		
		}
		
	}
	
	class SeeBankBalanceListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
			intefaceView.addShowBalancleOFATM();
			int[] mas;
			try {
				mas = theModel.getMoney();
				intefaceView.showATMBalance().putText10(Integer.toString(mas[0]));
				intefaceView.showATMBalance().putText50(Integer.toString(mas[1]));
				intefaceView.showATMBalance().putText100(Integer.toString(mas[2]));
				intefaceView.showATMBalance().putText200(Integer.toString(mas[3]));
				
			} catch (SQLException e1) {
				intefaceView.showMassage("The mistake happened");
			}
			
		}
		
	}
	
	class BalanceButtonOKListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addMantainanceActionPannel();
		}
		
	}

	class PutCardListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addPutNumberCard();
			
		}
		
	}
	
	class PutPinCodeListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addPutPinCode();
			
		}
		
	}
	
	class ChooseOperationListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			intefaceView.addChooseOperation();
			
		}
		
	}
}
